//
//  PersonInfoViewController.m
//  WeiWeiHaircut
//
//  Created by 高继鹏 on 15/10/16.
//  Copyright © 2015年 超群. All rights reserved.
//

#import "PersonInfoViewController.h"
#import "QZDesignerMsgCell.h"
#import "PersonMiddleCell.h"
#import "PersonLowerCell.h"
#import "MyWorksViewController.h"
#import "QZUserModel.h"


@interface PersonInfoViewController ()
{
    UITableView *_tableView;
    NSMutableArray *tableSource;
    QZUserModel *_userModel;
}

@end

@implementation PersonInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self titleWithSting:@"设计师主页"];
    [self addBtnOnNavWithTitle:@"返回" andImageName:@"返回" andTarget:self andAction:@selector(backAction) andFrame:CGRectMake(0, 0, 45, 20) andDirection:left];
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
    _tableView.backgroundColor = BACKGROUDCOLOR;
    [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([QZDesignerMsgCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([QZDesignerMsgCell class])];
    [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([PersonMiddleCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([PersonMiddleCell class])];
    [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([PersonLowerCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([PersonLowerCell class])];
    [self.view addSubview:_tableView];
    [self createData];
    [self requestData];
}
-(void)requestData
{
    [self requestWithKeys:@[@"user_id"] andValues:@[_designer_ID] andUrlKey:@"User.GetBaseInfo" isCache:YES];
    
}
-(void)request_POST_FinishValue:(id)value tagNSString:(NSString *)tag
{
    
    if ([tag isEqualToString:@"User.GetBaseInfo"]) {
        if ([value[@"data"][@"status"] intValue] == 100) {
            _userModel = [[QZUserModel alloc]initWithDictionary:value[@"data"][@"data"] error:nil];
            [_tableView reloadData];
        }
    }
}
- (void)createData
{
    tableSource = [[NSMutableArray alloc] init];
    [tableSource addObject:@[@"微微商城昵称",@"0",@"设计师（顾客）"]]; //0女性
    [tableSource addObject:@[@"学好街舞，报效父母"]];
    [tableSource addObject:@[@"北京市 海淀区"]];
    _tableView.dataSource = self;
    _tableView.delegate   = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}

#pragma mark - UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return 100;
    }
    else if (indexPath.row == 1) {
        return 88;
    }
    else if (indexPath.row == 2) {
        return 182;
    }else
        return 0;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 2) {
        MyWorksViewController *worksVc = [[MyWorksViewController alloc]init];
        worksVc.designer_ID = self.designer_ID;
        [self.navigationController pushViewController:worksVc animated:YES];
    }
}
#pragma mark - UITableViewDataSource
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        QZDesignerMsgCell *upperCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([QZDesignerMsgCell class]) forIndexPath:indexPath];
        upperCell.selectionStyle = UITableViewCellSelectionStyleNone;
        upperCell.contentView.backgroundColor = BACKGROUDCOLOR;
        upperCell.nickNameLabel.textColor = FiveOneColor;
        
        [upperCell.headImage sd_setImageWithURL:[NSURL URLWithString:_userModel.userimg] placeholderImage:[UIImage imageNamed:@"1123.jpg"]];
        upperCell.nickNameLabel.text = _userModel.nickName;
    
        NSString *imageName;
        if ([[QZUserInfo sex] isEqualToString:@"男"]) {
            imageName = @"男";
        }else if ([[QZUserInfo sex] isEqualToString:@"女"]){
            imageName = @"女";
        }else{
            upperCell.sexImage.hidden = YES;
        }
        upperCell.sexImage.image = [UIImage imageNamed:imageName];
        upperCell.goodAtLabel.text = _userModel.user_type;
        [upperCell loadStarViewWithStarValue:_userModel.user_star];
        
        return upperCell;
    }else if (indexPath.row == 1) {
        PersonMiddleCell *middleCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([PersonMiddleCell class]) forIndexPath:indexPath];
        middleCell.selectionStyle = UITableViewCellSelectionStyleNone;
        middleCell.contentView.backgroundColor = BACKGROUDCOLOR;
        middleCell.personSignTextView.textColor = FiveOneColor;
        middleCell.personSignTextView.text = _userModel.sign;
        middleCell.personSignTextView.font = [UIFont systemFontOfSize:16];

        return middleCell;
    }else{
        PersonLowerCell *lowCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([PersonLowerCell class]) forIndexPath:indexPath];
        lowCell.selectionStyle = UITableViewCellSelectionStyleNone;
        lowCell.contentView.backgroundColor = BACKGROUDCOLOR;
        lowCell.addressLabel.text = _userModel.userdizhi;
        lowCell.photoArr = _userModel.hair_img_list;
        return lowCell;
    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return tableSource.count;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

-(void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}





@end
